package com.csr.csrcheck.service.impl;

import com.csr.csrcheck.mapper.Stock_alterationMapper;
import com.csr.csrcheck.pojo.Stock_alteration;
import com.csr.csrcheck.service.Stock_alterationService;
import com.csr.csrcheck.service.ex.CompanyException;
import com.csr.csrcheck.util.PageResult;
import com.csr.csrcheck.util.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Stock_alterationServiceImpl implements Stock_alterationService {
    @Resource
    private Stock_alterationMapper stock_alterationMapper;

    public PageResult getlistPage(int pageNum, int pageSize, String shareholder_name, String type, String change_time) {
        return PageUtils.getPageResult(pageNum, pageSize, getPageInfo(pageNum, pageSize, shareholder_name, type, change_time));
    }

    private PageInfo<Stock_alteration> getPageInfo(int pageNum, int pageSize, String shareholder_name, String type, String change_time) {
        PageHelper.startPage(pageNum, pageSize);
        List<Stock_alteration> list = this.stock_alterationMapper.getlistPage(shareholder_name, type, change_time);
        if (list == null)
            throw new CompanyException("");
        return new PageInfo(list);
    }

    public void addStock_alteration(Stock_alteration stock_alteration) {
        int row = this.stock_alterationMapper.addStock_alteration(stock_alteration);
        if (row != 1)
            throw new CompanyException("");
    }

    public int updateStock_alteration(Stock_alteration stock_alteration) {
        int row = this.stock_alterationMapper.updateStock_alteration(stock_alteration);
        if (row != 1)
            throw new CompanyException("");
        return row;
    }

    public Stock_alteration findstock_alterationByid(int id) {
        Stock_alteration list = this.stock_alterationMapper.findstock_alterationByid(id);
        if (list == null)
            throw new CompanyException("");
        return list;
    }

    public int deletestock_alterationByid(int id) {
        int row = this.stock_alterationMapper.deletestock_alterationByid(id);
        if (row != 1)
            throw new CompanyException("");
        return row;
    }
}